package ui;


/**
 * A ScreenChanger is an example Runnable to be used with an EmpoweredWorker.
 * It has the ability to change the current screen for the DisplayContext.
 * @author Karl
 */
public class ScreenChanger implements Runnable {
    private Screen destination;
    private DisplayContext context;
    
    /** Creates a new instance of ScreenChanger */
    private ScreenChanger(DisplayContext context, Screen destination) {
        this.destination = destination;
        this.context = context;
    }
    
    /**
     * @return this as a convenience
     */
    public ScreenChanger setDestination(Screen destination) {
        this.destination = destination;
        return this;
    }
    
    public static ScreenChanger toScreen(Screen destination) {
        return new ScreenChanger(destination.getContext(), destination);
    }
    
    public void run() {
        context.setScreen(destination);
    }
}
